#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
using namespace std;
#define MAX 5010
char a[MAX],b[MAX];
int init();
int main()
{
    scanf("%s%s", a + 1, b + 1);
    int ans = init();
    //交换a,b
    swap(a,b);
    ans = min(ans, init());
    cout << ans << endl;
    return 0;
}
int init()
{
    int m = strlen(a + 1), n = strlen(b + 1);
    int flag = 0;
    for (int j = 1; j <= m; j++)
    {
        int temp = j;
        for (int k = 1; k <= n && temp <= m; k++)
        {
            if (a[temp] == b[k] || a[temp] == '?' || b[k] == '?')
                temp++;
            else
                break;
        }
        if (temp - j == n)
        {
            return m;
        }
        if (temp == m + 1)
        {
            flag = m - j + 1;
            break;
        }
    }
    return m + n - flag;
}